package com.qf.fmw.service.impl;

import com.qf.fmw.dao.OrderDao;

import com.qf.fmw.dao.impl.OrderDaoImpl;
import com.qf.fmw.entity.bo.OrderBo;
import com.qf.fmw.entity.vo.RespResult;
import com.qf.fmw.service.OrderService;

import java.util.List;

public class OrderServiceImpl implements OrderService {
    private OrderDao orderDao =new OrderDaoImpl();

    // 查询所有订单
    @Override
    public RespResult showAllOrders() {
        List<OrderBo> orderList = orderDao.selectAllOrders();
        if (orderList == null || orderList.isEmpty()) {
            return RespResult.respError("未找到订单", null);
        }
        return RespResult.respSuccess("找到订单", orderList);
    }

    @Override
    public RespResult sendOrder(int orderId) {
        boolean updated = orderDao.updateOrderStatus(orderId, 2); // Assuming status '2' means 'shipped'
        if (updated) {
            return RespResult.respSuccess("订单状态更新成功", null);
        } else {
            return RespResult.respError("订单状态更新失败", null);
        }
    }

    // 搜索订单
    @Override
    public RespResult searchOrders(String userName, Integer orderState) {
        List<OrderBo> orderList = orderDao.searchOrders(userName, orderState);
        if (orderList == null || orderList.isEmpty()) {
            return RespResult.respError("未找到匹配的订单", null);
        }
        return RespResult.respSuccess("找到匹配的订单", orderList);
    }


    @Override
    public RespResult updateOrderStatus(int orderId, int orderState) {
        boolean updated = orderDao.updateOrderStatus(orderId, orderState);
        if (updated) {
            return RespResult.respSuccess("订单状态更新成功", null);
        } else {
            return RespResult.respError("订单状态更新失败", null);
        }
    }
}

/**/